[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
fgets() Read a String from Stream
#include <stdio.h>
char *fgets(string,n,stream);
char *string; Storage location
int n; Number of characters stored
FILE *stream; Pointer to file structure
fgets() reads characters from 'stream' and stores them in 'string'.
fgets() stops reading at the first new-line character (in which case
the new-line itself will be stored in 'stream'); at the end of the
stream; or when 'n'-1 characters have been read, whichever comes
first. A null character ('\0') is appended at the end of 'stream'.
Returns: The resultant string. A NULL value is returned if
there's an error or end-of-file condition. Because
EOF is a legitimate value that may be read from
'stream', use ferror() or feor() to determine whether
an error or end-of-file condition exists.
Notes: fgets() is similar to gets(), but gets() replaces the
new-line character with the null character. Also,
gets() reads only from stdin.
-------------------------------- Example ---------------------------------
This example gets a line of input from 'stream'.
#include <stdio.h>
char string[50], *newstring;
FILE *stream;
main()
{
if ((stream = fopen("new.dta","r+")) != NULL) {
newstring = fgets(string,50,stream);
}
}
See Also:
fgets()
puts()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson